<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <title>Document</title>
</head>
<body>
    <button>get</button>
    <button>post</button>
    <button>ajax</button>

    <script>
        const btns = document.querySelectorAll('button');
        //配置baseUrl(简化url)
        axios.defaults.baseURL = 'http://127.0.0.1:8000';
        btns[0].onclick = function(){
            //get请求 
            axios.get('/axios-server',{
                //url参数
                params:{
                    id:100,
                    qq:7
                },
                //请求头信息
                Headers:{
                    name:'wzw',
                    age:21
                }
            }).then(value =>{//数据的获取
                console.log(value);
            })
        }
        btns[1].onclick = function(){
            axios.post('/axios-server', 
            {
                    username :"admin",
                    password: "admin"
                },{
                //请求体
               
                //url参数
                params:{
                    id:100,
                    qq:9
                },
                //请求头信息
                headers:{
                    width:150,
                    height:183
                }
                
            })
        }
        btns[2].onclick = function(){
            axios({
                //请求方法
                method :'POST',
                //url
                url:'/axios-server',
                //url参数
                params:{
                    vip:10,
                    lever:100
                },
                //头信息
                headers:{
                    a:100,
                    b:3000
                },
                //请求体参数
                data:{
                    username:"admin",
                    password:123456
                }
            }).then(response=>{
                console.log(response);
                //响应状态码
                console.log(response.status);
                //响应状态字符串
                console.log(response.statusText);
                //响应体
                console.log(response.data);
                //响应头信息
                console.log(response.headers);
            })
        }
    </script>
</body>
</html>